package gewu.suleju.controller;

import gewu.suleju.model.vo.PageInfoAll;
import gewu.suleju.model.vo.Result;
import gewu.suleju.sevice.ISearchHouseInforAllService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Set;
import java.util.concurrent.TimeUnit;

@Controller
@RequestMapping("searchHouseInfor")
public class SearchHouseInforController {
    @Autowired
    private ISearchHouseInforAllService searchHouseInforAllService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private PageInfoAll pageInfoAll;

    @ResponseBody//将java对象转化成json对象
    @PostMapping("search")
    public Result searchHouseInfor(String selectValue, String regionOrSubway, String checkboxsValue,
                                    @RequestParam(defaultValue = "1")int pageNum,
                                    @RequestParam(defaultValue = "5") int pageSize){
        //System.out.println(pageSize);

        //清空redis
        Set<String> keys = redisTemplate.keys("*");
        redisTemplate.delete(keys);

        searchHouseInforAllService.findHouseInforAllPage(selectValue, regionOrSubway, checkboxsValue, pageSize);

        pageInfoAll = (PageInfoAll)redisTemplate.opsForValue().get(pageNum+"");

        return new Result("200","房子分页",pageInfoAll);
    }
}
